<!doctype html>

<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>wind management</title>
<link href="/statics/css/admin_style.css" rel="stylesheet" />
<script src="/statics/js/jquery.js"></script>
<script src="/statics/js/supe.js"></script>

</head>
<body>
<div class="wrap">
  <div class="h_a">功能说明</div>
  <div class="prompt_text">
    <ul>
      <li>此功能允许管理员手动维护地区的联动关系及新增区域，用户在编辑个人资料时更准确地定义归属区域。</li>
      <li>此功能的维护涉及全站所有的地域联动调用，请管理员根据实际的行政地域调整变化修改。</li>
    </ul>
  </div>
  <div class="h_a">地区管理</div>
  <div class="pop_loading" id="J_loading" style="display:none"></div>
  <div class="table_full J_loading_show">
    <table width="100%">
      <col class="th" />
      <col width="400" />
      <col />
      <tr>
        <th>选择地区</th>
        <td><div class="yarnball mr20 fl">
            <ul class="cc">
            <?php foreach($route as $item) { ?>
              <li><a class="J_yarnball" href="<?=admin_url('config/areadata', array('pid'=>$item['areaid']));?>"><?=$item['name']?></a><em></em></li>
            <?php } ?>
            </ul>
          </div>

          <a href="#" id="J_region_set" style="float:left;margin-top:7px;">更换省市&gt;&gt;</a>
          </td>
        <td><div class="fun_tips"></div></td>
      </tr>
    </table>
  <form class="J_ajaxForm J_loading_show" action="" method="post">
    <input id="J_parentid" type="hidden" value="<?=$areaid;?>" name="pid" />
      <table width="100%" id="J_table_list">
        <col width="100" />
        <col />
        <col width="200" />
        <col width="150" />
        <col class="300" />
        <thead>
          <tr class="h_a">
            <th>ID</th>
            <th>名称</th>
            <th>拼音</th>
            <th>顺序</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody id="J_region_list">
          <?php foreach ($list as $item) { ?>
          <tr id="J_tr<?=$item['areaid'];?>">
            <th><?=$item['areaid'];?></th>
            <th><?=$item['name'];?></th>
            <th><?=$item['pinyin'];?></th>
            <th><?=$item['ordnum'];?></th>
            <td>
              <?php if($level < 2){ ?>
              <a href="<?=admin_url('config/areadata', array('pid'=>$item['areaid']));?>" class="mr10">[下级区域]</a>
              <?php }else{ ?>
              <span class="mr10">[已到末尾]</span>
              <?php } ?>
              <a href="<?=admin_url('config/areadata/edit', array('areaid'=>$item['areaid']));?>" class="mr10 J_region_edit">[编辑]</a>
              <a href="<?=admin_url('config/areadata/del', array('areaid'=>$item['areaid']));?>" class="mr10 J_region_del">[删除]</a>
            </td>
          </tr>
          <?php } ?>
        </tbody>
      </table>
      <div class="p10"><a href="<?=admin_url('config/areadata/add', array('pid'=>$pid));?>" class="link_add J_region_add">添加区域</a></div>
    </div>
    <div class="btn_wrap">
      <div class="btn_wrap_pd">
         <a title="添加" href="<?=admin_url('config/areadata/add', array('pid'=>$pid));?>" class="btn J_region_add"><span class="add"></span>添加区域</a>
      </div>
    </div>
  </form>
  </div>

</div>
<template source='TPL:admin.common.footer' />
<script language="javascript">
Supe.use('dialog', function() {

    $('#J_region_set').click(function(){
        var url = '?m=config&c=areadata&a=dlglist&dialog=1'
        var dialog = $.dialog({title:'选择省市', width:'400px', cancel:true, cancelValue:'取消'});
        $.get(url, function(data){
            dialog.content(data);
        });
    });

    $(".J_region_add").click(function(e){
        e.preventDefault();
        $.dialog.open($(this).attr('href') + '&dialog=1',
        {
            width:'600px', height:'400px', title:'添加区域信息'
        });
    });

    $("#J_region_list").on('click', '.J_region_edit', function(e){
        e.preventDefault();
        $.dialog.open($(this).attr('href') + '&dialog=1',
        {
            width:'600px', height:'400px', title:'编辑区域信息'
        });
    });

    $("#J_region_list").on('click', '.J_region_del', function(e){
        e.preventDefault();
        var areaid = $(this).parent().parent().attr('id').replace('J_tr', '');
        var delurl = $(this).attr('href');
        $.dialog.confirm('确定要删除该区域吗？',function(){
            $.dialog.close();
            $.getJSON(delurl,function(data){
                if(data.success == true)
                    callback.delete(areaid);
                else if(data.message)
                    $.dialog.alert(data.message)
                else
                    $.dialog.alert('删除操作失败')
            });
        });
    });
});
var callback = {
    update: function(areaid){
        $tr = $('#J_tr' + areaid);
        $.getJSON('/front.php?m=webdata&c=area&areaid=' + areaid, function(data){
            $tr.find('th:eq(1)').html(data.name);
            $tr.find('th:eq(2)').html(data.pinyin);
            $tr.find('th:eq(3)').html(data.ordnum);
        })
        $tr.addClass('high_light');
        $(document).scrollTop($tr.offset().top);
        setTimeout(function(){$('tr').removeClass('high_light')}, 1000);
    },
    insert: function(areaid){
        $.getJSON('/front.php?m=webdata&c=area&areaid=' + areaid, function(data){
            var s = '<tr class="high_light" style="display:none;" id="J_tr' +data.areaid+ '">'
                  +   '<th>' +data.areaid+ '</th>'
                  +   '<th>' +data.name+ '</th>'
                  +   '<th>' +data.pinyin+ '</th>'
                  +   '<th>' +data.ordnum+ '</th>'
                  +   '<td>'
                  +     (data.level < 2 ? '<a href="<?=admin_url('config/areadata');?>&pid=' +data.areaid+ '" class="mr10">[下级区域]</a>' : '<span class="mr10">[已到末尾]</span>')
                  +     '<a href="<?=admin_url('config/areadata/edit');?>&areaid=' +data.areaid+ '" class="mr10 J_region_edit">[编辑]</a>'
                  +     '<a href="<?=admin_url('config/areadata/del');?>&areaid=' +data.areaid+ '" class="mr10 J_region_del">[删除]</a>'
                  +   '</td>'
                  + '</tr>';
            $(document).scrollTop($('tr:last').offset().top);
            $(s).appendTo('#J_region_list')
                .fadeIn(1000, function(){
                    $(this).removeClass('high_light');
                });
        });
    },
    delete: function(areaid){
        $tr = $('#J_tr' + areaid);
        $tr.addClass('high_light')
           .fadeOut(1000, function(){
                $(this).remove();//$.dialog.alert('该区域已经被删除。');
            });
    }
};
</script>
</body>
</html>
